package com.xxs.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.jfinal.template.Engine;
import com.xxs.directive.InfoListDirective;
import com.xxs.directive.NodeListDirective;
import com.xxs.interceptor.GlobalInterceptor;
import com.xxs.method.QueryUtils;

public class Config extends JFinalConfig {
	 public static String base;

    /**
     * 配置常量
     */
    public void configConstant(Constants me) {
        loadPropertyFile("config.txt");
        me.setDevMode(true);
        me.setError404View("/common/404.html");
        me.setError500View("/common/500.html");
        base = JFinal.me().getContextPath();
    }

    /**
     * 配置插件
     */
    public void configPlugin(Plugins me) {
        me.add(new EhCachePlugin());
    }

    /**
     * 配置全局拦截器
     */
    public void configInterceptor(Interceptors me) {
        me.add(new GlobalInterceptor());
    }

    /**
     * 配置处理器
     */
    public void configHandler(Handlers me) {
    }

    /**
     * 初始化常量
     */
    public void afterJFinalStart() {
        super.afterJFinalStart();
    }
    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 80, "/", 5);
    }

	@Override
	public void configEngine(Engine me) {
		me.addDirective("nodeList", new NodeListDirective());
		me.addDirective("infoList", new InfoListDirective());
		me.addSharedObject("query", new QueryUtils());
		me.addSharedFunction("/common/text.html");
		me.addSharedFunction("/common/layout.html");
	}

	public void configRoute(Routes me) {
		me.add(new FrontRoutes());
		me.add(new AdminRoutes());
	}

}